﻿<%@ Page Language="C#" AutoEventWireup="true" Codebehind="ClassList2.aspx.cs" Inherits="LabMS.Web.CommonPage.ClassList2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>班级列表</title>
    <link type="text/css" rel="stylesheet" href="../style/screen.css" />
    <link href="../css/jquery.wysiwyg.css" rel="stylesheet" type="text/css" />
    <!--[if lte IE 6]>
    <link type="text/css" rel="stylesheet" href="../../style/ie6.css" />
    <![endif]-->
    <!--[if lte IE 7]>
    <link type="text/css" rel="stylesheet" href="../../style/ie7.css" />
    <![endif]-->

    <script type="text/javascript" src="../../js/Common.js"></script>

</head>
<body class="mainBody">
    <form id="form1" runat="server">
        <div class="main">
            <p>
                <input type="button" id="Select" class="button" name="Select" onclick="" value="选择" />
            </p>
        </div>
        <div class="main">
            <asp:GridView ID="Gv_Class" AutoGenerateColumns="false" AllowPaging="true" PageSize="10"
                DataKeyNames="ID" runat="server" Width="100%" OnSelectedIndexChanging="Gv_Class_SelectedIndexChanging"
                CssClass="infoTable">
                <Columns>
                    <asp:TemplateField ItemStyle-CssClass="checkBox">
                        <HeaderTemplate>
                            <asp:CheckBox ID="CBAll" runat="server" />
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox ID="chk" runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="ID" ShowHeader="false" ItemStyle-CssClass="none" HeaderStyle-CssClass="none" />
                    <asp:BoundField DataField="Class_Code" HeaderText="班级编号" />
                    <asp:BoundField DataField="Class_Name" HeaderText="班级名称" />
                    <asp:BoundField DataField="Class_Professional" HeaderText="专业" />
                    <asp:BoundField DataField="Class_StudentNum" HeaderText="班级人数" />
                </Columns>
                <HeaderStyle CssClass="header" />
            </asp:GridView>
        </div>
    </form>

    <script type="text/javascript" src="../js/jQuery/jquery-1.3.1.js"></script>

    <script type="text/javascript" src="../js/jQuery/jquery.tooltip.js"></script>

    <script type="text/javascript" src="../js/jQuery/jquery.bgiframe.js"></script>

    <script type="text/javascript" src="../js/jQuery/jquery.validate.js"></script>

    <script type="text/javascript" src="../js/jQuery/jquery.json-1.3.min.js"></script>

    <script type="text/javascript" src="../js/site.js"></script>

    <script type="text/javascript">

        $(function(){
            /* 修改样式 */
            $("#Gv_Class > tbody > tr:even").not(":first").addClass("even");
            $("#Gv_Class > tbody > tr").not(":first")
                .hover(
                    function(){
                        $(this).addClass("hover");
                    },
                    function(){
                        $(this).removeClass("hover");
                });

            /* 全选 */
            $("#Gv_Class > tbody > tr:first :checkbox").click(function(){
                if ($(this).attr("checked")){
                    $("#Gv_Class :checkbox").attr("checked", "checked");
                    cbChanged();
                } else{
                    $("#Gv_Class :checkbox").attr("checked", "");
                    cbChanged();
                }
            });

            /* Checkbox事件 */
            $("#Gv_Class :checkbox").not(":first").click(cbChanged);

            cbChanged();
            
            $("#Select").click(function(){
                var r = {};
                r.Items = [];
                
                $("#Gv_Class > tbody > tr").not(":first").each(function(){
                    if ($(this).find("input[type='checkbox']").attr("checked")) {
                        var item = {};
                        item.ID = $(this).find("td:nth-child(2)").html();
                        item.Code = $(this).find("td:nth-child(3)").html();
                        item.Name = $(this).find("td:nth-child(4)").html();
                        item.Pro = $(this).find("td:nth-child(5)").html();
                        item.Num = $(this).find("td:nth-child(6)").html();
                        r.Items.push(item);
                    }
                });
                // alert($.toJSON(r));
                window.returnValue = r;// $.toJSON(r);
                window.close();
            });
        });

        /* 新窗口打开链接 */
        function openUrl(url) {
            window.open(url, "winName", 'height=600,width=900,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes, resizable=no,location=no, status=no');
        }

        /* 检测Checkbox的选择状态，更改button的disabled属性 */
        function cbChanged(){
            var hasChecked = false;
            var allChecked = true;
            $("#Gv_Class :checkbox").not(":first").each(function(index, domEle){
                var curChecked = $(domEle).attr("checked");
                if (!hasChecked && curChecked){
                    hasChecked = true;
                }

                allChecked &= curChecked;
            });

            if (hasChecked){
                $("#Select").attr("disabled", "");
            } else {
                $("#Select").attr("disabled", "disabled");
            }

            if (allChecked){
                $("#Gv_Class :checkbox").filter(":first").attr("checked", "checked");
            } else {
                $("#Gv_Class :checkbox").filter(":first").attr("checked", "");
            }
        }

    </script>

</body>
</html>
